package com.sercomm.ott.mediaplayer.fragment_test;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.sercomm.ott.mediaplayer.R;

import java.util.List;

/**
 * Created by davis on 17-10-23.
 */

public class NewsAdapter extends ArrayAdapter<News>{
    private int resourceId;
    public NewsAdapter(Context context, int textViewResourceId, List<News> object){
        super(context,textViewResourceId,object);
        resourceId = textViewResourceId;
    }
    @Override
    public View getView(int position, View convertView, ViewGroup parent){
        News news = getItem(position);
        View view;
        ViewHolder viewHolder;
        if(convertView == null){
            view = LayoutInflater.from(getContext()).inflate(resourceId,null);
            viewHolder = new ViewHolder();
            viewHolder.newTitleText = (TextView)view.findViewById(R.id.news_title);
            view.setTag(viewHolder);
        }else {
            view = convertView;
            viewHolder = (ViewHolder) view.getTag();
        }
        viewHolder.newTitleText.setText(news.getTitle());
        //TextView newTitleText = (TextView) view.findViewById(R.id.news_title);
        //newTitleText.setText(news.getTitle());
        return view;
    }

    class ViewHolder{
        TextView newTitleText;
    }
}
